package com.mvp.shq.washer.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RatingBar;
import android.widget.TextView;

import com.mvp.shq.washer.R;
import com.mvp.shq.washer.entity.shop.ProductComment;
import com.mvp.shq.washer.utils.ImageUtil;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/10/10.
 */

public class ProductCommentAdapter extends RecyclerView.Adapter<ProductCommentAdapter.ViewHolder> {


    private Context context;
    private List<ProductComment> datas;
    private ImageUtil imageUtil;
    public ProductCommentAdapter(Context mContext, List<ProductComment> list) {
        context = mContext;
        datas = list;
        imageUtil = new ImageUtil(context);
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_product_comment, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        ProductComment comment = datas.get(position);
        holder.tvCommentContent.setText(comment.getContent());
        holder.tvCommentTime.setText(comment.getCreateDate());
        if (comment.getAnonym().equals("1")){
            holder.tvUsername.setText(comment.getAnonymName());
        }else {
            holder.tvUsername.setText(comment.getUserNickname());
        }
        holder.rbNormal.setRating((float) comment.getStar());
        if (comment.getReplyInfo() == null || TextUtils.isEmpty(comment.getReplyInfo())){
            holder.llFeedback.setVisibility(View.GONE);
        }else {
            holder.llFeedback.setVisibility(View.VISIBLE);
            holder.tvFeedbackContent.setText(comment.getReplyInfo());
        }
        imageUtil.loadUrlImage(comment.getFaceurl(),holder.imgUserface);
    }

    @Override
    public int getItemCount() {
        return datas.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.img_userface)
        ImageView imgUserface;
        @BindView(R.id.tv_username)
        TextView tvUsername;
        @BindView(R.id.rb_normal)
        RatingBar rbNormal;
        @BindView(R.id.tv_comment_time)
        TextView tvCommentTime;
        @BindView(R.id.tv_comment_content)
        TextView tvCommentContent;
        @BindView(R.id.tv_feedback_content)
        TextView tvFeedbackContent;
        @BindView(R.id.ll_feedback)
        LinearLayout llFeedback;
        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
